package cn.itcast.solr;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.junit.Test;

public class queryDocument1 {
    @Test
    public void testWrite()throws Exception{
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/collection1");
        SolrQuery query = new SolrQuery("title:apple OR title:锤子");
        query.setSort("price", SolrQuery.ORDER.asc);
        QueryResponse response = solrServer.query(query);
        //List<Item> results = response.getBeans(Item.class);
         SolrDocumentList results = response.getResults();
        System.out.println("共搜索到：--"+results.size()+"条数据");
        for (SolrDocument result : results) {
            System.out.println("result = " + result.toString());
        }
        solrServer.commit();
    }
}
